@extends('layouts.app')

@section('content')
    <div class="container">
        <div class="row">
            <div class="panel panel-default">
                <div class="panel-heading">设置</div>
                <div class="panel-body">
                    <form class="form-horizontal" role="form" method="POST" action="{{ route('configsave') }}">
                        {{ csrf_field() }}
                        <input id="module" type="hidden" name="module" value="{{ $module }}">
                        <div class="form-group{{ $errors->has('wechat_name') ? ' has-error' : '' }}">
                            <label for="wechat_name" class="col-md-2 control-label">公众号名称</label>
                            <div class="col-md-6">
                                <input id="wechat_name" type="text" class="form-control" name="wechat_name" value="{{ old('wechat_name',$config[$module]['wechat_name']) }}" required autofocus>
                                @if ($errors->has('wechat_name'))
                                    <span class="help-block">
                                            <strong>{{ $errors->first('wechat_name') }}</strong>
                                        </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('wechat_id') ? ' has-error' : '' }}">
                            <label for="wechat_id" class="col-md-2 control-label">公众号原始id</label>
                            <div class="col-md-6">
                                <input id="wechat_id" type="text" class="form-control" name="wechat_id" value="{{ old('wechat_id', $config[$module]['wechat_id']) }}" required>
                                @if ($errors->has('wechat_id'))
                                    <span class="help-block">
                                            <strong>{{ $errors->first('wechat_id') }}</strong>
                                        </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('wechat_no') ? ' has-error' : '' }}">
                            <label for="wechat_no" class="col-md-2 control-label">微信号</label>
                            <div class="col-md-6">
                                <input id="wechat_no" type="text" class="form-control" name="wechat_no" value="{{ old('wechat_no', $config[$module]['wechat_no']) }}" required>
                                @if ($errors->has('wechat_no'))
                                    <span class="help-block">
                                            <strong>{{ $errors->first('wechat_no') }}</strong>
                                        </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('wechat_appid') ? ' has-error' : '' }}">
                            <label for="wechat_appid" class="col-md-2 control-label">AppID</label>
                            <div class="col-md-6">
                                <input id="wechat_appid" type="text" class="form-control" name="wechat_appid" value="{{ old('wechat_appid', $config[$module]['wechat_appid']) }}" required>
                                @if ($errors->has('wechat_appid'))
                                    <span class="help-block">
                                            <strong>{{ $errors->first('wechat_appid') }}</strong>
                                        </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('wechat_appsecret') ? ' has-error' : '' }}">
                            <label for="wechat_appsecret" class="col-md-2 control-label">AppSecret</label>
                            <div class="col-md-6">
                                <input id="wechat_appsecret" type="text" class="form-control" name="wechat_appsecret" value="{{ old('wechat_appsecret', $config[$module]['wechat_appsecret']) }}" required>
                                @if ($errors->has('wechat_appsecret'))
                                    <span class="help-block">
                                            <strong>{{ $errors->first('wechat_appsecret') }}</strong>
                                        </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('wechat_token') ? ' has-error' : '' }}">
                            <label for="wechat_token" class="col-md-2 control-label">Token</label>
                            <div class="col-md-6">
                                <input id="wechat_token" type="text" class="form-control" name="wechat_token" value="{{ old('wechat_token', $config[$module]['wechat_token']) }}" required>
                                @if ($errors->has('wechat_token'))
                                    <span class="help-block">
                                            <strong>{{ $errors->first('wechat_token') }}</strong>
                                        </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('wechat_qr') ? ' has-error' : '' }}">
                            <label for="wechat_qr" class="col-md-2 control-label">公众号二维码</label>
                            <div class="col-md-6">
                                <input type="hidden" name="wechat_qr" id="wechat_qr" class="form-control file" value="{{ old('wechat_qr', $config[$module]['wechat_qr']) }}"/>
                                <input type="file" name="image" id="image" class="form-control image"/>
                                @if ($errors->has('wechat_qr'))
                                    <span class="help-block">
                                            <strong>{{ $errors->first('wechat_qr') }}</strong>
                                        </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('wechat_type') ? ' has-error' : '' }}">
                            <label for="wechat_type" class="col-md-2 control-label">微信号类型</label>
                            <div class="col-md-6">

                                <select name="wechat_type" class="form-control">
                                    <option value="1">订阅号</option>
                                    <option value="2">服务号</option>
                                    <option value="3">认证订阅号</option>
                                    <option value="4" selected="selected">认证服务号</option>
                                </select>
                                @if ($errors->has('wechat_type'))
                                    <span class="help-block">
                                            <strong>{{ $errors->first('wechat_type') }}</strong>
                                        </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('to_kf_keyword') ? ' has-error' : '' }}">
                            <label for="to_kf_keyword" class="col-md-2 control-label">转在线客服</label>
                            <div class="col-md-6">
                                <input id="to_kf_keyword" type="text" class="form-control" name="to_kf_keyword" value="{{ old('to_kf_keyword', $config[$module]['to_kf_keyword']) }}" required>
                                @if ($errors->has('to_kf_keyword'))
                                    <span class="help-block">
                                            <strong>{{ $errors->first('to_kf_keyword') }}</strong>
                                        </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-4">
                                <button type="submit" class="btn btn-primary">
                                    保存
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(document).on('ready', function () {
            $(".image").fileinput({
                uploadAsync: false,
                //showUpload: false,
                //showPreview: false,
                //showCaption: false,
                showRemove : false,
                language: 'zh',
                uploadUrl: '{{ route("imageupload") }}?_token='+window.Laravel.csrfToken,
                allowedFileExtensions: ['jpg', 'png', 'gif']
            });
            $(".image").on("fileuploaded", function (event, data, previewId, index) {
                $("#wechat_qr").val(data.response.path);
            });
        });
    </script>
@endsection
